app.controller("specificationController",function ($scope,$controller,specificationService) {

    $controller("baseController",{$scope:$scope});

    $scope.list=[];//页面显示的列表

    $scope.searchEntity={}; //搜索用的数据

    $scope.entity={spec:{},specOptionList:[]};//一个规格属性 一个规格选项的list集合 编辑保存用的实体

    $scope.search=function(page,rows){

        specificationService.findPage(page,rows,$scope.searchEntity).then(function (result) {

            $scope.list=result.data.rows;
            $scope.pageModel.totalItems=result.data.total;
        });

    }

    //添加一行
    $scope.addOption=function(){

        $scope.entity.specOptionList.push({});

    }
    //删除一行 根据下标
    $scope.delOption=function ($index) {
        $scope.entity.specOptionList.splice($index,1)
        
    }
    $scope.save=function() {

        if ($scope.entity.spec.id) {


            specificationService.update($scope.entity).then(function (result) {

                if (result.data.success) {

                    $scope.reloadList();
                } else {

                    alert(result.data.message);
                }

            });


        } else {
            specificationService.save($scope.entity).then(function (result) {

                if (result.data.success) {

                    $scope.reloadList();
                } else {

                    alert(result.data.message);
                }

            });

        }

    }

        $scope.edit = function (id) {
            specificationService.findOne(id).then(function (result) {

                $scope.entity = result.data;

            });

        }

        $scope.dele = function () {

           specificationService.dele($scope.selectedIds).then(function (result) {


               if (result.data.success) {

                   $scope.reloadList();
               } else {

                   alert(result.data.message);
               }
           });

        }

    });